/**
 * 
 */
package com.roshan.web.security.domain;

import java.util.Collection;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.StringUtils;

public class RoarAuthenticationToken extends UsernamePasswordAuthenticationToken {

    private static final long serialVersionUID = 100L;

    private String userUri;

    private String firstName;

    private String lastName;

    private String fullName;

    private String securityQuestion;

    private String securityAnswer;

    private boolean checkPassword = true;

    private boolean checkMFA = true;

    private boolean passwordExpired = false;

    public RoarAuthenticationToken(Object principal, Object credentials,
            Collection<? extends GrantedAuthority> authorities, String firstName, String lastName, String userUri,
            String securityQuestion, String securityAnswer, boolean checkPassword, boolean checkMFA) {
        super(principal, credentials, authorities);
        this.userUri = userUri;
        this.firstName = firstName;
        this.lastName = lastName;
        this.securityQuestion = securityQuestion;
        this.securityAnswer = securityAnswer;
        this.checkPassword = checkPassword;
        this.checkMFA = checkMFA;
        this.fullName = this.getFullName();
    }

    public String getUserUri() {
        return this.userUri;
    }

    public void setUserUri(String userUri) {
        this.userUri = userUri;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFullName() {

        this.fullName = buildFullName();
        return this.fullName;
    }

    @SuppressWarnings("nls")
    private String buildFullName() {

        StringBuilder fullNameBuilder = new StringBuilder();
        boolean emptyFirstName = !StringUtils.hasText(this.firstName);
        boolean emptyLastName = !StringUtils.hasText(this.lastName);
        if (emptyFirstName && emptyLastName) {
            return fullNameBuilder.append("User").toString();
        } else if (!emptyFirstName && emptyLastName) {
            return fullNameBuilder.append(this.firstName).toString();
        } else if (emptyFirstName && !emptyLastName) {
            return fullNameBuilder.append(this.lastName).toString();
        }
        fullNameBuilder.append(this.firstName);
        fullNameBuilder.append(" ");
        fullNameBuilder.append(this.lastName);
        return fullNameBuilder.toString();
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getSecurityQuestion() {
        return this.securityQuestion;
    }

    public void setSecurityQuestion(String securityQuestion) {
        this.securityQuestion = securityQuestion;
    }

    public String getSecurityAnswer() {
        return this.securityAnswer;
    }

    public void setSecurityAnswer(String securityAnswer) {
        this.securityAnswer = securityAnswer;
    }

    public boolean isCheckPassword() {
        return this.checkPassword;
    }

    public void setCheckPassword(boolean checkPassword) {
        this.checkPassword = checkPassword;
    }

    public boolean isCheckMFA() {
        return this.checkMFA;
    }

    public void setCheckMFA(boolean checkMFA) {
        this.checkMFA = checkMFA;
    }

    public void setPasswordExpired(boolean passwordExpired) {
        this.passwordExpired = passwordExpired;
    }

    public boolean isPasswordExpired() {
        return this.passwordExpired;
    }

}
